package ui.activity.mine;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import net.ck.hzq.R;
import net.ck.hzq.TobuyApplication;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import Bean.MessagecenterBean;
import base.BaseAct;
import base.BaseFra;
import butterknife.BindView;
import coom.Constants;
import event.NetErrorEvent;
import ui.activity.mine.biz.MessageCenterBiz;
import ui.activity.mine.component.DaggerMessageCenterComponent;
import ui.activity.mine.contract.MessageCenterContract;
import ui.activity.mine.module.MessageCenterModule;
import ui.activity.mine.presenter.MessageCenterPresenter;
import ui.adapter.FragAdp;
import ui.fragment.MessageCenterFra;
import util.SysUtils;
import widget.tab.TabPageIndicator;


/**
 * 消息中心
 * Created by chenjian on 18/2/22.
 */

public class MessageAct extends BaseAct implements MessageCenterContract.View {


    @Inject
    MessageCenterPresenter presenter;
    @Inject
    MessageCenterBiz biz;

    @BindView(R.id.my_tabs)
    TabPageIndicator myTab;
    @BindView(R.id.my_vp)
    ViewPager vp;

    public List<BaseFra> fragments;
    List<String> titles = new ArrayList<>();
    @BindView(R.id.number1)
    TextView number1;
    @BindView(R.id.number2)
    TextView number2;
    @BindView(R.id.number3)
    TextView number3;
    @BindView(R.id.number4)
    TextView number4;

    private SharedPreferences sp;

    @Override
    protected void setRoot() {
//        setTitleBar("#0099E6");
        setContentView(R.layout.activity_messagecenter);
    }

    @Override
    protected void setup() {
        setToolBar(getResources().getString(R.string.messagecenter), "");
        DaggerMessageCenterComponent.builder().messageCenterModule(new MessageCenterModule(this)).build().inject(this);
        presenter.setBiz(biz);
    }

    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        sp = getSharedPreferences("ToBuy", Context.MODE_PRIVATE);
        fragments = new ArrayList<>();
        titles.add(getResources().getString(R.string.lang_ti));
        titles.add(getResources().getString(R.string.lang_gong));
        titles.add(getResources().getString(R.string.lang_ding));
        titles.add(getResources().getString(R.string.lang_shi));
        for (int i = 1; i < titles.size() + 1; i++) {
            MessageCenterFra fra = new MessageCenterFra();
            Bundle bundle = new Bundle();
            bundle.putInt(Constants.KEYSTRING, i);
            fra.setArguments(bundle);
            fragments.add(fra);
        }
        vp.setPageMargin(SysUtils.dip2px(this, 0f));
        vp.setOffscreenPageLimit(titles.size());
        vp.setAdapter(new FragAdp(this.getSupportFragmentManager(), titles, fragments));
        myTab.setViewPager(vp);
        setTabPagerIndicator();
        presenter.setNumberType(sp.getString("id", "0"), 1);
        presenter.setNumberType(sp.getString("id", "0"), 2);
        presenter.setNumberType(sp.getString("id", "0"), 3);
        presenter.setNumberType(sp.getString("id", "0"), 4);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    /**
     * 设置标题栏
     */

    private void setTabPagerIndicator() {
        myTab.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_NOWEIGHT_EXPAND_SAME);// 设置模式，一定要先设置模式
//        myTab.setDividerColor(Color.parseColor("#0099E6"));// 设置分割线的颜色
        myTab.setDividerPadding(SysUtils.dip2px(TobuyApplication.getInstance(), 0));
        myTab.setIndicatorColor(Color.parseColor("#0099E6"));// 设置底部导航线的颜色
        myTab.setTextColorSelected(Color.parseColor("#0099E6"));// 设置tab标题选中的颜色
        myTab.setTextColor(Color.parseColor("#333333"));// 设置tab标题未被选中的颜色
        myTab.setTextSize((int) SysUtils.sp2px(TobuyApplication.getInstance(), 14));// 设置字体大小
    }


    @Override
    public void loadMoreComplete() {

    }

    @Override
    public void hasLoadMore(boolean b) {

    }

    @Override
    public void refreshComplete() {

    }

    @Override
    public void upDateUI(List<MessagecenterBean.DataBean.ItemsBean> bean, int readNumber) {

    }

    @Override
    public void upDateNumber(int type, int number) {
        switch (type) {
            case 1:
                if (number == 0) {
                    number1.setVisibility(View.INVISIBLE);
                } else {
                    number1.setText(number + "");
                    number1.setVisibility(View.VISIBLE);
                }
                break;
            case 2:
                if (number == 0) {
                    number2.setVisibility(View.INVISIBLE);
                } else {
                    number2.setText(number + "");
                    number2.setVisibility(View.VISIBLE);
                }
                break;
            case 3:
                if (number == 0) {
                    number3.setVisibility(View.INVISIBLE);
                } else {
                    number3.setText(number + "");
                    number3.setVisibility(View.VISIBLE);
                }
                break;
            case 4:
                if (number == 0) {
                    number4.setVisibility(View.INVISIBLE);
                } else {
                    number4.setText(number + "");
                    number4.setVisibility(View.VISIBLE);
                }
                break;
        }
    }
}
